package com.wjw.java.basic.convert_;

import java.lang.Boolean;

/**
 * 基本数据类型转为String:基本数据类型 + ""
 */
public class ConvertBasicToString {
    public static void main(String[] args) {
        //基本数据类型  ---> String
        int i = 10;
        float f = 20.1f;
        double d = 30.1;
        boolean b = false;
        String s1 = i + "";
        String s2 = f + "";
        String s3 = d + "";
        String s4 = b + "";
        System.out.println("s1:"+s1);
        System.out.println("s2:"+s2);
        System.out.println("s3:"+s3);
        System.out.println("s4:"+s4);

        //String ---> 基本数据类型,使用包装类的xxx.ParseXxx()方法
        int i1 = Integer.parseInt(s1);
        float f1 = Float.parseFloat(s2);
        double d1 = Double.parseDouble(s3);
        boolean b1 = Boolean.parseBoolean(s4);
        System.out.println("i1:"+i1);
        System.out.println("f1:"+f1);
        System.out.println("d1:"+d1);
        System.out.println("b1:"+b1);

        //字符串转为字符数组
        String str = "abcdef";
        char[] chars = str.toCharArray();
        for (int j = 0; j < chars.length; j++) {
            System.out.println(chars[j]);
        }
        
    }
}
